#include <stdio.h>

char *filename = "file.txt";

int main(void)
{
    FILE * fp;
    double f = 1254.3412215678;

    double buf[1024];

    int n;

    if ((fp = fopen(filename, "r")) != NULL) {
        double dou;

        while ((n = fscanf(fp, "%lf", &dou)) > 0) {
            printf("n:%d, value:%.10lf\n", n, dou);
        }

    } else {
        printf("数据%s不存在,正在创建...\n", filename);

        if ((fp = fopen(filename, "w")) != NULL) {
            buf[0] = f;
            int n = fprintf(fp, "%.11lf\n", f);
            printf("写入%d个小数!\n", n);

        } else {
            printf("创建文件%s失败!\n", filename);
        }

    }
    return 0;
}
